//
// Created by whz on 2022/5/22.
//

#include "stop_watch.h"

StopWatch::StopWatch() {
    startPoint = std::chrono::steady_clock::now();
    stopPoint = std::chrono::steady_clock::now();
}

void StopWatch::start() {
    startPoint = std::chrono::steady_clock::now();
}

void StopWatch::stop() {
    stopPoint = std::chrono::steady_clock::now();
}

/* 返回us */
long StopWatch::getElapsedTime() {
    stopPoint = std::chrono::steady_clock::now();
    long res = std::chrono::duration_cast<std::chrono::microseconds>(stopPoint - startPoint).count();
    return res;
}
double StopWatch::getElapsedSeconds() {
  stopPoint = std::chrono::steady_clock::now();
  long res = std::chrono::duration_cast<std::chrono::microseconds>(stopPoint - startPoint).count();
  return res/1000000.0;
}